using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Drawing;
using System.Diagnostics;
namespace Test {
	class ImgVis {
		static void MainX() {
			string filename="test.png";
			SQL dal=new SQL("server=pon-wpsq12-db;database=putawaydearnepallet;integrated security=sspi;");
			DataTable tab=dal.Query(@"SELECT convert(char(16),created,20)date,count(*)
FROM directory_putaway(NOLOCK) where created between convert(datetime,'25/05/2012',103) 
and convert(datetime,'31/05/2012',103)+1  and bonus_no='hfr'  
group by convert(char(16),created,20)");
			string minDateStr=tab.Compute("min(date)",null).ToString();
			string maxDateStr=tab.Compute("max(date)",null).ToString();
			DateTime minDate=DateTime.ParseExact(minDateStr,"yyyy-MM-d HH:mm:ss.fff".Substring(0,minDateStr.Length-1),null);
			DateTime maxDate=DateTime.ParseExact(maxDateStr,"yyyy-MM-d HH:mm:ss.fff".Substring(0,minDateStr.Length-1),null);
			int barwidth=4;
			int width=barwidth*(int)(maxDate-minDate).TotalMinutes+20;
			using(Bitmap bmp=new Bitmap(width,100))
			using(Graphics g=Graphics.FromImage(bmp))
			{
				g.Clear(Color.White);
				foreach(DataRow row in tab.Rows)
				{
					DateTime date=DateTime.ParseExact(row[0].ToString(),"yyyy-MM-d HH:mm:ss.fff".Substring(0,row[0].ToString().Length-1),null);
					int x=(int)(date-minDate).TotalMinutes;
					int y=(int)row[1]*5;
					//g.DrawLine(Pens.Black,x,bmp.Height,x,bmp.Height-y);
					g.DrawRectangle(Pens.Black,x*barwidth,bmp.Height-y,barwidth,y);
				}
				bmp.Save(filename);
			}
			Process.Start(filename);
		}
	}
}
